<html>
<head>
    <title>双预防系统</title>
    <link rel="stylesheet" href="../../../assets/theme-chalk/index.css">
    <link rel="stylesheet" href="../../../style.css">
    <link rel="stylesheet" href="../../../swipebox.css">
    <script type='text/javascript' src='../../../assets/bundle.js' charset='utf-8'></script>
    <script type='text/javascript' src='../../../assets/bundle.js' charset='utf-8'></script>
    <script type='text/javascript' src='../../../assets/jquery-1.11.2.min.js' charset='utf-8'></script>
    <script type='text/javascript' src='../../../assets/jquery.swipebox.min.js' charset='utf-8'></script>
    <script type='text/javascript' src='../../../assets/echarts.min.js' charset='utf-8'></script>
    <script type='text/javascript' src='../../../js/common.js' charset='utf-8'></script>
    <script type='text/javascript' src='../../../js/registers.js' charset='utf-8'></script>
    <script type='text/javascript' src='../../../js/component.js' charset='utf-8'></script>
    <link rel="stylesheet" href="../user-visual/plugin/layui/css/layui.css">
    <script src="../user-visual/plugin/layui/layui.all.js"></script>
    <style>
        body {
            background: #F0F2F6;
        }

        .main-head {
            background: #fff;
            padding-left: 10px;
            padding-top: 10px;
            margin-bottom: 0px;
            border: solid 1px #fff;
        }

        .chart-outer {
            height: 200px;
        }

        .inputW {
            width: 150px;
        }

        .itemW {
            width: 200px;
        }

        .formLabelWidth {
            width: 100px;
        }
        .text {
            font-size: 14px;
        }

        .item {
            padding: 18px 0 0 0;
        }
        .chart-wrap{
            height: 300px;
        }
        .el-switch{
            padding-top: 10px;
        }
        .el-checkbox-group{
            padding-top: 5px;
        }
        .el-input{
            width: 120px;
        }
    </style>
</head>
<body>
<div class="page" id="page-monitor">
    <el-tabs v-model="activeName"  type="border-card" @tab-click="handleClick">
        <el-tab-pane label="智慧用电" name="smartPower">

            <el-row>
                <el-col :span="4" style="height:calc(100% - 71px)">
                    <el-menu class="el-menu-vertical-demo" @select="handleSelect" default-active="0" >
                        <el-menu-item v-for="(item, index) in devList" :index="index">
                            <i class="el-icon-news"></i>
                            <span slot="title">{{item.DeviceName}}</span>
                        </el-menu-item>
                    </el-menu>
                    <el-pagination
                            @current-change="handleCurrentChange"
                            :current-page="param.pageno"
                            small
                            :page-size="param.pagesize"
                            layout="total, prev, pager, next"
                            :total="total">
                    </el-pagination>
                </el-col>
                <el-col :span="20">
                    <div class="main-head">
                        <el-row :gutter="12">
                            <el-col :span="12" >
                                <el-card shadow="hover" style="height: 350px;">
                                    <span class="text item">设备详情</span>
                                    <el-button @click="paramShow()" style="float: right" type="danger" size="small">参数设置<i class="el-icon-s-tools el-icon--right"></i></el-button>
                                    <el-divider></el-divider>
                                    <div class="text item">设备名称:　　{{device.DeviceName}}</div>
                                    <div class="text item">设备编号:　　{{device.DeviceId}}</div>
                                    <div class="text item">设备类型:　　{{device.deviceModel}}</div>
                                    <div class="text item">设备状态:　　<span v-if="device.online==1">在线</span><span v-else-if="device.online==0">离线</span></div>
                                    <div class="text item">最近时间:　　{{device.updateTime}}</div>
                                </el-card>
                            </el-col>
                            <el-col :span="12">
                                <el-card shadow="hover" style="height: 350px;">
                                    <span class="text">实时数据</span>
                                    <el-divider></el-divider>

                                    <el-col :span="6" v-for="d in paramData" key="d">
                                        <el-tag  　style="white-space:nowrap;margin-top:10px">
                                            {{d.dp_name}}：{{Math.abs(d.dp_value)}} {{d.dp_unitid}}
                                        </el-tag>
                                    </el-col>
                                </el-card>
                            </el-col>
                        </el-row>
                        <el-row >
                            <div class="tag-group">
                                <span class="tag-group__title">历史数据</span>
                                <el-date-picker
                                        v-model="day"
                                        value-format="yyyy-MM-dd"
                                        type="date"
                                        placeholder="选择日期" style="width: 170px"
                                        @change="dateChange">
                                </el-date-picker>
                                <el-tag
                                        v-for="(item,index) in hisData.fields"
                                        :key="item.title"
                                        :type="paramIndex==index?'':'info'"
                                        effect="dark"
                                        @click="hisClick(index)"
                                        style="cursor: pointer">
                                    {{ item.title }}
                                </el-tag>
                            </div>
                            <el-col :span="24" style="margin-top: 10px">
                                <chart-elex :option="elOptions"></chart-elex>
                            </el-col>
                        </el-row>
                    </div>
                </el-col>
            </el-row>

        </el-tab-pane>
        <el-tab-pane label="智慧水源" name="smartWater">
            <el-row>
                <el-col :span="4" style="height:calc(100% - 71px)">
                    <el-menu class="el-menu-vertical-demo" @select="handleSelect"  default-active="0"  >
                        <el-menu-item v-for="(item, index) in devList" :index="index">
                            <i class="el-icon-news"></i>
                            <span slot="title">{{item.DeviceName}}</span>
                        </el-menu-item>
                    </el-menu>
                    <el-pagination
                            @current-change="handleCurrentChange"
                            :current-page="param.pageno"
                            small
                            :page-size="param.pagesize"
                            layout="total, prev, pager, next"
                            :total="total">
                    </el-pagination>
                </el-col>

                <el-col :span="20">
                    <div class="main-head">
                        <el-row :gutter="12">
                            <el-col :span="12">
                                <el-card shadow="hover" style="height: 350px;">
                                    <span class="text item">设备详情</span>
                                    <el-divider></el-divider>
                                    <div class="text item">设备名称:　　{{device.DeviceName}}</div>
                                    <div class="text item">设备编号:　　{{device.DeviceId}}</div>
                                    <div class="text item">设备类型:　　{{device.deviceModel}}</div>
                                    <div class="text item">设备状态:　　<span v-if="device.online==1">在线</span><span v-else-if="device.online==0">离线</span></div>
                                    <div class="text item">最近时间:　　{{device.updateTime}}</div>
                                </el-card>
                            </el-col>
                            <el-col :span="12" >
                                <el-card shadow="hover" style="height: 350px;">
                                    <span class="text item">实时数据</span>
                                    <el-divider></el-divider>

                                    <el-col :span="6" v-for="d in paramData" key="d">
                                        <el-tag  　style="white-space:nowrap;margin-top:10px">
                                            {{d.dp_name}}：{{d.dp_value}} {{d.dp_unitid}}
                                        </el-tag>
                                    </el-col>
                                </el-card>
                            </el-col>
                        </el-row>
                        <el-row>
                            <div class="tag-group">
                                <span class="tag-group__title">历史数据</span>
                                <el-date-picker
                                        v-model="day"
                                        value-format="yyyy-MM-dd"
                                        type="date"
                                        placeholder="选择日期" style="width: 170px"
                                        @change="dateChange">
                                </el-date-picker>
                                <el-tag
                                        v-for="(item,index) in hisData.fields"
                                        :key="item.title"
                                        :type="paramIndex==index?'':'info'"
                                        effect="dark"
                                        @click="hisClick(index)"
                                        style="cursor: pointer">
                                    {{ item.title }}
                                </el-tag>
                            </div>
                            <el-col :span="24" style="margin-top: 10px">
                                <chart-elex :option="wOptions"></chart-elex>
                            </el-col>
                        </el-row>
                    </div>
                </el-col>
            </el-row>
        </el-tab-pane>
        <el-tab-pane label="门禁系统" name="AccessControl">
            <el-row>
                <el-col :span="4" style="height:calc(100% - 71px)">
                    <el-menu class="el-menu-vertical-demo" @select="handleSelect"  default-active="0" >
                        <el-menu-item v-for="(item, index) in devList" :index="index">
                            <i class="el-icon-news"></i>
                            <span slot="title">{{item.DeviceName}}</span>
                        </el-menu-item>
                    </el-menu>
                    <el-pagination
                            @current-change="handleCurrentChange"
                            :current-page="param.pageno"
                            small
                            :page-size="param.pagesize"
                            layout="total, prev, pager, next"
                            :total="total">
                    </el-pagination>
                </el-col>

                <el-col :span="20">
                    <div class="main-head">
                        <el-row :gutter="12">
                            <el-col :span="12">
                                <el-card shadow="hover" style="height: 350px;">
                                    <span class="text item">设备详情</span>
                                    <el-divider></el-divider>
                                    <div class="text item">设备名称:　　{{device.DeviceName}}</div>
                                    <div class="text item">设备编号:　　{{device.DeviceID}}</div>
                                    <div class="text item">设备类型:　　{{device.deviceModel}}</div>
                                    <div class="text item">设备状态:　　<span v-if="device.online==1">在线</span><span v-else-if="device.online==0">离线</span></div>
                                    <div class="text item">最近时间:　　{{device.updateTime}}</div>
                                </el-card>
                            </el-col>
                            <el-col :span="12" >
                                <el-card shadow="hover" style="height: 350px;">
                                    <span class="text item">实时数据</span>
                                    <el-divider></el-divider>

                                    <el-col :span="6" v-for="d in paramData" key="d">
                                        <el-tag  　style="white-space:nowrap;margin-top:10px">
                                            {{d.dp_name}}：{{Math.abs(d.dp_value)}} {{d.dp_unitid}}
                                        </el-tag>
                                    </el-col>
                                </el-card>
                            </el-col>
                        </el-row>
                        <el-row style="margin-top: 15px">
                            <span class="tag-group__title">历史数据</span>
                            <el-date-picker
                                    v-model="day"
                                    value-format="yyyy-MM-dd"
                                    type="date"
                                    placeholder="选择日期" style="width: 170px"
                                    @change="dateChange">
                            </el-date-picker>
                            <el-tag
                                    v-for="(item,index) in hisData.fields"
                                    :key="item.title"
                                    :type="paramIndex==index?'':'info'"
                                    effect="dark"
                                    @click="hisClick(index)"
                                    style="cursor: pointer">
                                {{ item.title }}
                            </el-tag>
                            <el-col :span="24" style="margin-top: 10px">
                                <chart-elex :option="intrusionOptions"></chart-elex>
                            </el-col>
                        </el-row>

                    </div>
                </el-col>
            </el-row>
        </el-tab-pane>
    </el-tabs>
    <el-dialog title="参数设置" :visible.sync="paramVisible" width="80%">
        <form class="layui-form" id="registersForm">

        </form>
    </el-dialog>
</div>

<script>

    let vuePage = new Vue({
        el: '#page-monitor',
        data: {
            param:{
                pagesize: 10,
                pageno: 1,
                projectNo:"",
                deviceType2:'smartPower',
            },
            total:"",
            search: '',
            devList:'',
            activeName:'smartPower',
            device:'',
            paramData:'',
            selectDev:'',
            elOptions:{},
            wOptions:{},
            intrusionOptions:{},
            hisData:{},
            paramIndex:0,
            day:'',
            paramVisible:false,
            paramForm:{
                name: '',
                region: '',
                date1: '',
                date2: '',
                delivery: false,
                type: [],
                resource: '',
                desc: ''
            },
        },

        methods: {
            handleCurrentChange(page){

                const loading = this.$loading({
                    lock: true,
                    text: 'Loading',
                    spinner: 'el-icon-loading',
                    background: 'rgba(0, 0, 0, 0.7)'
                });
                setTimeout(() => {
                    loading.close();
                }, 1000);
                this.param.pageno = page;
                this.getDeviceData();
            },
            handleSelect(key){
                this.hisData = [];
                const loading = this.$loading({
                    lock: true,
                    text: 'Loading',
                    spinner: 'el-icon-loading',
                    background: 'rgba(0, 0, 0, 0.7)'
                });
                setTimeout(() => {
                    loading.close();
                }, 1000);
                this.selectDev = this.devList[key];
                this.getDeviceData();
                this.getDeviceHis();
            },
            hisClick(key){
                this.paramIndex = key;
                let chartData = {
                    title:this.hisData.fields[key].title,
                    yData:[],
                    xData:[],
                    unit:this.hisData.fields[key].unit,
                };
                let list  = this.hisData;
                for (let ind in list.values){
                    chartData.yData.push(list.values[ind][this.hisData.fields[key].name]);
                    chartData.xData.push(list.values[ind].updateTime.split('T')[1])
                }
                this.drawChart(chartData);
            },
            handleClick(tab){
                this.hisData ={};
                const loading = this.$loading({
                    lock: true,
                    text: 'Loading',
                    spinner: 'el-icon-loading',
                    background: 'rgba(0, 0, 0, 0.7)'
                });
                setTimeout(() => {
                    loading.close();
                }, 1000);
                this.activeName = tab.name;
                this.param.deviceType2 = tab.name;
                this.device = {};
                this.devList = [];
                this.paramData = [];

                this.getDevList();
            },
            getDevList(){
                HttpUtil.get('Device/List',this.param).success((res)=>{
                    this.devList = res.data;
                    this.total = res.total;
                    this.selectDev = res.data[0];
                    this.getDeviceData();
                    this.getDeviceHis();
                })
            },
            getDeviceData(){
                HttpUtil.get('device/getById',{deviceId:this.selectDev.DeviceID,isEnvir:1}).success((res)=>{
                    res.data.updateTime = res.data.updateTime ? res.data.updateTime.replace('T',' '):'',
                        this.device = res.data;
                    HttpUtil.get('device/Monitor',{deviceId:this.selectDev.DeviceID,isEnvir:1}).success((res)=>{
                        this.paramData = res.data;
                    })
                })
            },
            getDeviceHis(){
                HttpUtil.get('device/hisData',{deviceNo:this.selectDev.DeviceID,pagesize:2888,dat: this.day,isEnvir:1}).success((res)=>{
                    res.data.fields=[
                        {"name":"UA","title":"A相电压","unit":"V"},
                        {"name":"UB","title":"B相电压","unit":"V"},
                        {"name":"UC","title":"C相电压","unit":"V"},
                        {"name":"IA","title":"A相电流","unit":"A"},
                        {"name":"IB","title":"B相电流","unit":"A"},
                        {"name":"IC","title":"C相电流","unit":"A"},
                        {"name":"I_Zero","title":"漏电流","unit":"mA"},
                        {"name":"PA","title":"A相功率","unit":"KW"},
                        {"name":"PB","title":"B相功率","unit":"KW"},
                        {"name":"PC","title":"C相功率","unit":"KW"},
                        {"name":"PSum","title":"总功率","unit":"KW"},
                        {"name":"ESum","title":"总电能","unit":"KWh"},
                        {"name":"PFSum","title":"总功率因数","unit":""},
                        {"name":"SSum","title":"总视在功率","unit":"KVA"},
                        {"name":"EA","title":"A相电能","unit":"KWh"},
                        {"name":"EB","title":"B相电能","unit":"KWh"},
                        {"name":"EC","title":"C相电能","unit":"KWh"},
                        {"name":"Temp1","title":"温度1","unit":"℃"},
                        {"name":"Temp2","title":"温度2","unit":"℃"},
                        {"name":"Temp3","title":"温度3","unit":"℃"},
                        {"name":"Temp4","title":"温度4","unit":"℃"},
                    ]
                    this.hisData = res.data;
                    this.hisClick(0);
                })
            },
            drawChart(data){
                let options = {
                    toolbox: {
                        show: true,
                        feature: {
                            dataView: {readOnly: false},
                            magicType: {type: ['line', 'bar']},
                            restore: {},
                            saveAsImage: {}
                        }
                    },
                    title: {
                        left: 'center',
                        text: data.title,
                    },

                    tooltip:{
                        trigger: 'axis',
                    },
                    grid: {
                        top: '12%',
                        left: '1%',
                        right: '10%',
                        containLabel: true
                    },
                    xAxis: [
                        {
                            type : 'category',
                            data:data.xData
                        }
                    ],
                    yAxis: [
                        {
                            type : 'value',
                            name: '单位'+data.unit,

                        }
                    ],

                    dataZoom: [
                        {
                            show: true,
                            start: 94,
                            end: 100
                        },
                        {
                            type: 'inside',
                            start: 94,
                            end: 100,
                        },
                        {
                            show: false,
                            yAxisIndex: 0,
                            filterMode: 'empty',
                            width: 30,
                            height: '80%',
                            showDataShadow: false,
                            left: '93%'
                        }
                    ],
                    series : [
                        {
                            type: 'line',
                            data: data.yData,
                            name:'时间：电压',
                            // markLine: {
                            //     silent: true,
                            //     lineStyle: {
                            //         normal: {
                            //             color: 'red'                   // 这儿设置安全基线颜色
                            //         }
                            //     },
                            //     data: [{
                            //         yAxis:270
                            //     }],
                            //     label: {
                            //         normal: {
                            //             formatter: '报警\n基线'           // 这儿设置安全基线
                            //         }
                            //     },
                            // },
                        },
                    ],
                };
                switch (this.activeName) {
                    case 'smartPower':
                        this.elOptions = options;
                        break;
                    case 'smartWater':
                        this.wOptions = options;
                        break;
                    case 'AccessControl':
                        this.intrusionOptions = options;
                        break;
                }

            },
            dateChange(date){

                const loading = this.$loading({
                    lock: true,
                    text: 'Loading',
                    spinner: 'el-icon-loading',
                    background: 'rgba(0, 0, 0, 0.7)'
                });
                setTimeout(() => {
                    loading.close();
                }, 1000);
                this.day = date;
                this.paramIndex = 0;
                this.getDeviceHis();
            },

            /**
             * 设备控制
             * 采用以往的写法，直接复制过来。懒得改了。
             */

            paramShow(){
                this.paramVisible = true;
                    let tform = layui.form;
                    let layer = layui.layer;
                    //加载参数设置
                    //$("#spanDeviceParams").text(thisDeviceDes);
                setTimeout(()=>{
                    let listRegisters = "";
                    listRegisters += '<div class="layui-inline"><a class="layui-btn layui-btn-small layui-btn-normal btnReadAllRegisters"><i class="layui-icon">&#xe620;</i>一键读取</a></div>';
                    //判断设备型号，生成参数设置内容
                    let Registers = registers[this.selectDev.deviceModel];
                    let Operations = deviceOperations[this.selectDev.deviceModel];
                    for(let i = 0; i < Registers.length; i++) {
                        let plaseHolder = Registers[i].desc + "" + Registers[i].unit;
                        let elemHolder = "";
                        switch(Registers[i].inputtype) {
                            case "text":
                                elemHolder = '<input class="layui-input" readonly="readonly" id="' + Registers[i].addr + '" name="registersValue" placeholder="' + plaseHolder + '" autocomplete="off" style="width:200px;display: inline-block;">';
                                break;
                            case "switch":
                                elemHolder = '<div style="width:200px;display: inline-block;"><input type="checkbox" lay-filter="filter" value="1" lay-skin="switch" id="' + Registers[i].addr + '" name="registersValue" checked></div>';
                                break;
                            case "bit":
                                elemHolder = '<div style="width:auto;display: inline-block;">';
                                elemHolder += '<input type="hidden" id="bit_' + Registers[i].addr + '" value="unread" /> ';
                                for(let j = 0; j < Registers[i].bits.length; j++) {
                                    elemHolder += '<span style="font-size:8px">' + Registers[i].bitsdesc[j] + '</span>'
                                    elemHolder += '<input type="checkbox" value="' + Registers[i].bits[j] + '" lay-filter="filter" id="' + j + '_' + Registers[i].addr + '" name="registersValue">';
                                }
                                elemHolder += '</div>';
                                break;
                            case "picker":
                                for(let j = 0; j < Registers[i].length; j++) {
                                    elemHolder = '<label class="layui-form-label" style="width:100px">' + Registers[i][j].name + '：</label>';
                                    elemHolder += '<select id="' + j + '_' + Registers[i].addr + '" style="width:200px;display: inline-block;">';
                                    for(let k = 0; k < Registers[i][j].length; k++) {
                                        elemHolder += '<option value="' + Registers[i][j].values[k] + '"></option>';
                                    }
                                    elemHolder += '</select>';
                                }
                                elemHolder = '<input type="checkbox" class="layui-input" id="' + Registers[i].addr + '" name="registersValue" placeholder="' + plaseHolder + '" autocomplete="off" style="width:200px;display: inline-block;">';
                                break;
                            case "input":
                            default:
                                elemHolder = '<input class="layui-input" id="' + Registers[i].addr + '" name="registersValue" placeholder="' + plaseHolder + '" autocomplete="off" style="width:200px;display: inline-block;">';
                                break;
                        }
                        let set = '';
                        if(sessionStorage.getItem("roleId") > 2) {
                            set = '&nbsp;&nbsp;<a class="layui-btn layui-btn-small layui-btn-normal " style="margin-left: 10px;display: none"><i class="layui-icon">&#xe620;</i>设置</a>'
                        } else {
                            set = '&nbsp;&nbsp;<a class="layui-btn layui-btn-small layui-btn-normal setRegisters" style="margin-left: 10px;"><i class="layui-icon">&#xe620;</i>设置</a>';
                        }
                        listRegisters += '<div class="layui-form-item" style="margin: 0px;">' +
                            '<div class="layui-inline"><input class="hidden" name="addr" data-index="' + i + '" style="display: none;" value="' + Registers[i].addr + '">' +
                            '<label class="layui-form-label" style="width:100px">' + Registers[i].name + '：</label>' +
                            elemHolder +
                            ((Registers[i].access & 2) == 2 ? '&nbsp;&nbsp;<a class="layui-btn layui-btn-small layui-btn btnReadRegisters"><i class="layui-icon">&#xe857;</i>读取</a>' : '&nbsp;&nbsp;<span style="width:85px;display: inline-block;">&nbsp;</span>') +
                            ((Registers[i].access & 1) == 1 ? set : '&nbsp;&nbsp;<span style="width:85px;display: inline-block;">&nbsp;</span>') +
                            //'&nbsp;&nbsp;<span style="width: 200px;color: #FF5722;text-align: left;">'+Registers[i].unit+'</span>' +
                            '</div>' +
                            '</div>';
                    }
                    for(let i = 0; i < Operations.length; i++) {
                        if(i == 0) {
                            listRegisters += '<div class="layui-inline"><input class="hidden" data-index="' + i + '" name="addr" style="display: none;" value="' + Operations[i].addr + '"><input class="hidden" name="datavalue" style="display: none;" value="' + Operations[i].datavalue + '">' +
                                '<label class="layui-form-label" style="width:100px">控制操作：</label><a class="layui-btn layui-btn-small layui-btn-normal setRegisters1" style="margin-top: -1px;"><i class="layui-icon">&#xe620;</i>' + Operations[i].name + '</a>' +
                                '</div>';
                        } else {
                            listRegisters += '<div class="layui-inline"><input class="hidden" data-index="' + i + '"  name="addr" style="display: none;" value="' + Operations[i].addr + '"><input class="hidden" name="datavalue" style="display: none;" value="' + Operations[i].datavalue + '">' +
                                '&nbsp;&nbsp;<a class="layui-btn layui-btn-small layui-btn-normal setRegisters1" ><i class="layui-icon">&#xe620;</i>' + Operations[i].name + '</a>' +
                                '</div>';
                        }
                    }
                    $("#registersForm").html(listRegisters);

                    tform.render();
                    let self = this;
                    $('.setRegisters1').click( function() {
//找父级
                        let tempParent = $(this).closest(".layui-inline");
                        //找地址，判断控制，读取参数Operations
                        let tRegistersIndex = $(tempParent).find("input[name='addr']").data("index");
                        let addr = deviceOperations[self.selectDev.deviceModel][tRegistersIndex].addr;
                        let tvalue = $(tempParent).find("input[name='datavalue']").val();
                        let setParams = {};
                        setParams.deviceNo = self.selectDev.DeviceID;
                        setParams.dataCode = addr;
                        setParams.value = tvalue;
                        if(deviceOperations[self.selectDev.deviceModel][tRegistersIndex].pwdRequire) {
                            //prompt层
                            layer.prompt({
                                title: '输入操作密码，并确认',
                                formType: 1
                            }, function(pass, index) {
                                layer.close(layer.index);
                                if(pass != "99887766") {
                                    return;
                                }
                                layer.load();
                                HttpUtil.post('Collector/writeParam', setParams).success((result)=>{
                                    layer.closeAll('loading');
                                    layer.msg(result.errMsg || '操作成功', {
                                        icon: 1,
                                        zIndex: 9999999999
                                    }, 1500);
                                });

                            });
                        } else {
                            layer.load();
                            HttpUtil.post('Collector/writeParam', setParams).success((result)=>{
                                layer.closeAll('loading');
                                layer.msg(result.errMsg || '操作成功', {
                                    icon: 1,
                                    zIndex: 9999999999
                                }, 1500);
                            });
                        }
                        setTimeout(()=>{
                            layer.closeAll('loading');
                        },10000)
                    })
                    $('.setRegisters').click(function(){
                        //找父级
                        let tempParent = $(this).closest(".layui-inline");
                        //找地址，判断控制，读取参数
                        let tRegistersIndex = $(tempParent).find("input[name='addr']").data("index");
                        let addr = registers[self.selectDev.deviceModel][tRegistersIndex].addr;
                        let tvalue = $(tempParent).find("input[name='registersValue']").val();
                        if(tvalue.trim().length === 0) {
                            layer.msg('参数项内容不能为空', {
                                icon: 5,
                                zIndex: 9999999999
                            }, 1500);
                            return;
                        }
                        let setParams = {};
                        setParams.deviceNo = self.selectDev.DeviceID;
                        setParams.dataCode = addr;
                        setParams.value = tvalue;
                        if(registers[self.selectDev.deviceModel][tRegistersIndex].inputtype == "bit") {
                            let oldValue = $("#bit_" + addr).val();
                            if(oldValue == "unread") {
                                layer.msg('使能项必须读取后才能设置！', {
                                    icon: 5,
                                    zIndex: 9999999999
                                }, 1500);
                                return;
                            }
                            oldValue = parseInt(oldValue);
                            let ttValue = 0;
                            for(let j = 0; j < registers[self.selectDev.deviceModel][tRegistersIndex].bits.length; j++) {
                                let tElem = $("#" + j + "_" + addr);
                                if(tElem.prop("checked")) {
                                    ttValue = (1 << j) | ttValue;

                                }

                            }
                            //				ttValue = (oldValue & 0xfff0) | (ttValue & 0x000f); 只能修改温度使能
                            setParams.value = ttValue;
                        }
                        layer.load();
                        HttpUtil.post('Collector/writeParam', setParams).success((result)=>{
                            layer.closeAll('loading');
                            layer.msg(result.errMsg || '操作成功', {
                                icon: 1,
                                zIndex: 9999999999
                            }, 1500);
                        });
                        setTimeout(()=>{
                            layer.closeAll('loading');
                        },10000)
                    })
                    $('.btnReadAllRegisters').click(function(){
                        //找地址，判断控制，读取参数
                        let readParams = {};
                        readParams.deviceNo = self.selectDev.DeviceID;
                        //支持一键读取
                        readParams.dataCode = registers[self.selectDev.deviceModel][0].addr;
                        readParams.count = registers[self.selectDev.deviceModel].length;
                        layer.load();
                        HttpUtil.post('Collector/readParam', readParams).success((result)=>{
                            for(let i = 0; i < result.data.length; i++) {
                                //判断是否为checkbox
                                if(registers[self.selectDev.deviceModel][i].inputtype == "bit") {
                                    let oldValElem = $("#bit_" + registers[self.selectDev.deviceModel][i].addr);
                                    oldValElem.val(result.data[i]);
                                    for(let j = 0; j < registers[self.selectDev.deviceModel][i].bits.length; j++) {
                                        let tElem = $("#" + j + "_" + registers[self.selectDev.deviceModel][i].addr);
                                        if(((Number(result.data[i]) >> j) & 1) == 1) tElem.prop("checked", "checked")
                                        else tElem.removeProp("checked");
                                        tElem.val((Number(result.data[i]) >> j) & 1);
                                    }
                                } else if(registers[self.selectDev.deviceModel][i].inputtype == "switch") {
                                    let tElem = $("#" + registers[self.selectDev.deviceModel][i].addr);
                                    if(result.data[i] == "1") tElem.prop("checked", "checked")
                                    else tElem.removeProp("checked");
                                } else {
                                    let tElem = $("#" + registers[self.selectDev.deviceModel][i].addr);
                                    tElem.val(result.data[i]);
                                }
                                tform.render();
                                layer.closeAll('loading');
                            }
                        });
                        setTimeout(()=>{
                            layer.closeAll('loading');
                        },10000)
                    })
                    $('.btnReadRegisters').click(function() {
                        //找父级
                        let tempParent = $(this).closest(".layui-inline");
                        //找地址，判断控制，读取参数
                        let tRegistersIndex = $(tempParent).find("input[name='addr']").data("index");
                        let addr = registers[self.selectDev.deviceModel][tRegistersIndex].addr;
                        let readParams = {};
                        readParams.deviceNo = self.selectDev.DeviceID;
                        readParams.dataCode = addr;RHFI
                        readParams.count = 1;
                        layer.load();
                        HttpUtil.post('Collector/readParam', readParams).success((result)=>{

                                let tElem = $(tempParent).find("input[name='registersValue']");
                                tElem.val(result.data[0]);
                                //判断是否为checkbox

                                if(registers[self.selectDev.deviceModel][tRegistersIndex].inputtype == "bit") {
                                    let oldValElem = $("#bit_" + addr);
                                    oldValElem.val(result.data[0]);
                                    for(let j = 0; j < registers[self.selectDev.deviceModel][tRegistersIndex].bits.length; j++) {
                                        let tElem = $("#" + j + "_" + addr);
                                        if(((Number(result.data[0]) >> j) & 1) == 1) tElem.prop("checked", "checked")
                                        else tElem.removeProp("checked");
                                        tElem.val((Number(result.data[0]) >> j) & 1);
                                    }
                                } else if(registers[self.selectDev.deviceModel][tRegistersIndex].inputtype == "switch") {
                                    let tElem = $("#" + addr);
                                    if(result.data[0] == "1") tElem.prop("checked", "checked")
                                    else tElem.removeProp("checked");
                                }
                                tform.render();
                                layer.closeAll('loading');

                        });
                        setTimeout(()=>{
                            layer.closeAll('loading');
                        },10000)
                    })
                })
            },

        },
        created: function () {
            this.param.projectNo = SiteConfig.account.projectNo;
            this.day= TimeUtil.convertToString(new Date()).substr(0,10)
        },
        mounted: function () {
            this.getDevList();
        }
    });

</script>
</body>
</html>
